package com.team233.zuccecho.service.impl;

import com.team233.zuccecho.Bean.Feedback;
import com.team233.zuccecho.Bean.Statistics;
import com.team233.zuccecho.exception.EchoServiceException;
import com.team233.zuccecho.repository.FeedbackRepository;
import com.team233.zuccecho.service.inter.FeedbackInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;

@Service
public class FeedbackImpl implements FeedbackInterface {
    @Autowired
    private FeedbackRepository feedbackRepository;

    @Override
    public Integer summaryByTime(String time) throws EchoServiceException {
        int num=0;//填写问卷的学生人数
        Timestamp now = new Timestamp(System.currentTimeMillis());
        Calendar calendar = Calendar.getInstance();
        //获取当前时间的前一个小时
        calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - 1);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Timestamp time2= Timestamp.valueOf(df.format(calendar.getTime()));
        for (Feedback f:feedbackRepository.findAll()){
            if((f.getFb_time()).before(now)&&time2.before(f.getFb_time())){
                num++;
            }
        }
        return num;
    }

    @Override
    public Integer summaryBySubject(String subject) throws EchoServiceException {
        return feedbackRepository.findAll().size();
    }
}
